package com.it.utils;


import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.UUID;

@Component
public class UpLoadFile {

    @Resource
    private FileAliYunOssUtils fileAliYunOssUtils;

    public String uploadFile(MultipartFile file) throws IOException {
        // 获取原始的文件名
        String originalFilename = file.getOriginalFilename();
        //在oss中存储名字就是UUID + 文件的后缀名
        String objectName = UUID.randomUUID() + originalFilename.substring(originalFilename.lastIndexOf("."));
        String resultURL = fileAliYunOssUtils.upload(file.getBytes(), objectName);
        return resultURL;
    }
}
